<script type="text/html" template>
  <link rel="stylesheet" href="{{ layui.setter.base }}style/login.css?v={{ layui.admin.v }}-1" media="all">
</script>

    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

  <div class="layui-card layui-card-body layadmin-user-login-main">
    <div class="layadmin-user-login-box layadmin-user-login-header">
      <h2>WendaSNS</h2>
      <p>问答社区后台管理系统</p>
    </div>
    <form class="layadmin-user-login-box layadmin-user-login-body layui-form" action="{:url('/login/index')}" method="post">
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
        <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="管理员账号" class="layui-input">
      </div>
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
        <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input">
      </div>
{if configure('basis.captcha')}
      <div class="layui-form-item">
        <div class="layui-row">
          <div class="layui-col-xs7">
            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
            <input type="text" name="vcode" id="LAY-user-login-vercode" lay-verify="required" placeholder="图形验证码" class="layui-input">
          </div>
          <div class="layui-col-xs5">
            <div style="margin-left: 10px;">
              <img src="{:captcha_src()}" class="layadmin-user-login-codeimg" onclick="this.src=this.src+'?'+Math.random();" height="36">
            </div>
          </div>
        </div>
      </div>
{/if}

      <div class="layui-form-item">
        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="J_ajax_submit_login">登录</button>
      </div>
    </form>

  </div>
</div>

<script>
;!function(){
  var $ = layui.$
  ,setter = layui.setter
  ,admin = layui.admin
  ,form = layui.form
  ,router = layui.router()
  ,search = router.search;

  form.render();

  //提交
  form.on('submit(J_ajax_submit_login)', function(obj){
    var _form = $(obj.form),action = _form.prop('action'),method = _form.prop('method');
    //请求登入接口
    admin.req({
      url: action //实际使用请改成服务端真实接口
      ,type: method
      ,data: obj.field
      ,done: function(res){

        //请求成功后，写入 access_token
        layui.data(setter.tableName, {
          key: setter.request.tokenName
          ,value: res.data.access_token
        });
        
        //登入成功的提示与跳转
        layer.msg(res.msg, {
          offset: '15px'
          ,icon: 1
          ,time: 1000
        }, function(){
          location.hash = search.redirect ? decodeURIComponent(search.redirect) : '/';
        });
      }
    });
    return false;
  });
  
  
}();
</script>